﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;
using Utilities.QuickSql;
using MySql.Data;

namespace Deviseur_Cs2i_Car
{
    public partial class AdminMotorisation : Form
    {
        public AdminMotorisation()
        {
            InitializeComponent();

            Thread MotorisationThread = new Thread(new ThreadStart(getAllMotorisation_Thread));
            MotorisationThread.Start();
        }

        private void getAllMotorisation_Thread()
        {
            Invoke(new MethodInvoker(getAllMotorisation));
        }

        private void getAllMotorisation()
        {
            Table MotorisationVoiture = Program.Db.QueryTable("SELECT NumMotor, ChMotor, LibelleContenance, LibelleTypeMoteur FROM MOTORISATION M LEFT OUTER JOIN CONTENANCE C ON M.NumContenance = C.NumContenance LEFT OUTER JOIN TYPEMOTEUR T ON M.NumTypeMoteur = T.NumTypeMoteur");

            this.dataGridView1.Rows.Clear();

            foreach (Record r in MotorisationVoiture)
                this.dataGridView1.Rows.Add(r.Values[0], r.Values[1], r.Values[2], r.Values[3]);
        }

        private void AdminMotorisation_Activated(object sender, EventArgs e)
        {
            Thread MotorisationThread = new Thread(new ThreadStart(getAllMotorisation_Thread));
            MotorisationThread.Start();
        }
        private void buttonAddMotorisation_Click_1(object sender, EventArgs e)
        {
            AddMotorisation FenAddMotorisation = new AddMotorisation();
            FenAddMotorisation.ShowDialog();
        }

        private void buttonDelMotorisation_Click(object sender, EventArgs e)
        {
            MOTORISATION delMotorisation = new MOTORISATION();
            delMotorisation.delete_Motorisation(Convert.ToInt32(this.dataGridView1.SelectedRows[0].Cells[0].Value.ToString()));
            Thread TypeThread = new Thread(new ThreadStart(getAllMotorisation_Thread));
            TypeThread.Start();
        }

        private void ModifMotorisation_Click(object sender, EventArgs e)
        {
            AddMotorisation FenAddVoiture = new AddMotorisation(Convert.ToInt32(this.dataGridView1.SelectedRows[0].Cells[0].Value.ToString()));
            FenAddVoiture.ShowDialog();
        }
    }
}
